package com.yyfax.common.form;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.yyfax.common.R;

/**
 * Created by fuqiang on 2017/5/4.
 * 座机输入框
 * Copyright  2017 www.yylending.com. All Rights Reserved.
 */
public class FormLandLineView extends LinearLayout {
    /**
     * 区号
     */
    private EditText mAreaCode;

    /**
     * 座机/手机
     */
    private EditText mphone;

    /**
     * 分机号
     */
    private EditText mExtNum;

    public FormLandLineView(Context context) {
        super(context);
    }

    public FormLandLineView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public FormLandLineView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    void init(Context context, AttributeSet attrs) {
		TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.FormRow);
        setOrientation(LinearLayout.HORIZONTAL);
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.com_phone_formrow_layout, this);

        mAreaCode = (EditText) view.findViewById(R.id.com_area_code);
        mphone = (EditText) view.findViewById(R.id.com_phone);
        mExtNum = (EditText) view.findViewById(R.id.com_extension);

		boolean rightTextBold = ta.getBoolean(R.styleable.FormRow_rightTextBold, true);
		mAreaCode.getPaint().setFakeBoldText(rightTextBold);
		mphone.getPaint().setFakeBoldText(rightTextBold);
		mExtNum.getPaint().setFakeBoldText(rightTextBold);

		ta.recycle();
    }

    /**
     * 设置公司座机号
     */
    public void setComPhone(CharSequence areaCode, CharSequence phone, CharSequence extNum) {
        mAreaCode.setText(areaCode);
        mphone.setText(phone);
        mExtNum.setText(extNum);
    }

    /**
     * 获取区号
     */
    public String getAreaCode() {
        return mAreaCode.getText().toString();
    }

    /**
     * 获取公司座机号
     */
    public String getComPhone() {
        return mphone.getText().toString();
    }

    /**
     * 获取分机号
     */
    public String getExtNum() {
        return mExtNum.getText().toString();
    }


}
